
#pragma once

#include "gl/glew.h"
#include "mymath.h"

#include <string>
#include <map>

using namespace std;

//////////////////////////////////////////////////////////////////////////
// Uniforms related
// Disadvantage: when buffer gets dirty it gets fully reuploaded. It's possible
// to save on this and reupload only what's necessary. Some coding is required for this.
// However, usually uniform buffers aren't too large and reuploading everything should work fine.
#include "shaderDefs.h"

namespace EggNine {

class UniformBlock {
protected:
    mutable GLvoid* m_data;
    mutable bool m_dirty;
    GLsizeiptr m_size;
    GLuint m_id;
    string m_name;

    // In some cases purpose might become stream_draw (material properties for instance)
    GLenum m_purpose;

    UniformBlock(const char* name, int size, void* data, GLenum purpose);

public:
    virtual ~UniformBlock();

    void BindToProgram(GLuint program, GLuint bindingSlot) const;
    void BindToState(GLuint bindingSlot) const;
    virtual void Update() const;
    virtual void SetData(void* data);
    virtual void SetData(void* data) const;
    const string& Name() const { return m_name; }
};
typedef map<string, const UniformBlock*> UniformMap;


} // EggNine